package com.example.librarysysee.model;

import lombok.Data;

import java.util.Collections;

@Data
public class Result<T> {
    public Integer code;
    public String errmsg;
    public T data;

    /**
     * successful
     * static <T> 静态方法使用泛型必须在加static后加<T>
     */
    public static <T>Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(200);
        return result;
    }
    /**
     * default
     */
    public static <T>Result<T> fail(String errmsg){
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setErrmsg(errmsg);
        return result;
    }
    public static <T>Result<T> fail(T data, String errmsg){
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(-1);
        result.setErrmsg(errmsg);
        return result;
    }
    public static <T>Result<T> unLogin(){
        Result<T> result = new Result<>();
        result.setCode(-2);
        result.setErrmsg("用户未登录");
        return result;
    }

}
